<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <style type="text/css">
        .el-main {
            position: absolute;
            top: 70px;
            bottom: 0px;
            left: 200px;
            right: 10px;
            padding: 0;
        }

    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <el-container>
        <el-header class="main-header" style="height:70px;">
            <nav class="navbar navbar-static-top" :class=''>
                <!-- Logo -->
                <a href="#" class="logo" style="text-align:center">
                    <span class="logo-lg"><img src="../img/logo.png"></span>
                </a>
                <div class="right-menu">
                    <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                    <el-dropdown class="avatar-container right-menu-item" trigger="click">
                        <div class="avatar-wrapper">
                            <img src="../img/user2-160x160.jpg" class="user-avatar">
                            {{username}}
                        </div>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item divided>
                                <el-button type="text" @click="openEditPwd()">
                                    修改密码
                                </el-button>
                            </el-dropdown-item>
                            <el-dropdown-item divided>
                                <a href="/logout.do">
                                        <span style="display:block;">
                                            退出
                                        </span>
                                </a>
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </nav>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu>
                    <el-submenu v-for="menu in menuList" :index="menu.path">
                        <template slot="title">
                            <i class="fa" :class="menu.icon"></i>
                            {{menu.title}}
                        </template>
                        <template v-for="child in menu.children">
                            <el-menu-item :index="child.path">
                                <a :href="child.linkUrl" target="right">{{child.title}}</a>
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-container>
                <iframe name="right" class="el-main" src="akl.jpg" width="100%" height="880px" frameborder="0"></iframe>
            </el-container>
        </el-container>
    </el-container>
    <!-- 修改密码 -->
    <div class="add-form">
        <el-dialog title="修改密码" :close-on-click-modal="false" :show-close="false" width="30%"
                   :visible.sync="dialogFormVisible">
            <template>
                <el-tab v-model="activeName" type="card">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="20">
                                <el-form-item label="用户名" prop="username">
                                    <el-input v-model="formData.username"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="20">
                                <el-form-item label="新密码" prop="password">
                                    <el-input show-password v-model="formData.password"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="20">
                                <el-form-item label="手机号" prop="telephone">
                                    <el-input v-model="formData.telephone"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="验证码">
                                    <el-input v-model="formData.code"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                &nbsp;&nbsp;
                                <el-button :disabled="disabled" @click="sendValidateCode()" type="primary">
                                    {{btn_text}}
                                </el-button>
                            </el-col>
                        </el-row>
                    </el-form>

                </el-tab>
            </template>

            <div slot="footer" class="dialog-footer">
                <el-button @click="editCancel()">取消</el-button>
                <el-button type="primary" @click="editPassword()">确定</el-button>
            </div>
        </el-dialog>
    </div>
</div>

</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/healthmobile.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            username: '',//当前登录用户的用户名
            menuList: [],
            activeName: 'first',//添加/编辑窗口Tab标签名称
            btn_text: '获取验证码',
            formData: {},//表单数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            rules: {//校验规则
                username: [{required: true, message: '此为必填项', trigger: 'blur'}],
                password: [{required: true, message: '此为必填项', trigger: 'blur'}],
                telephone: [{required: true, message: '此为必填项', trigger: 'blur'}]
            }
        },
        created() {
            //发送ajax请求，请求Controller获取当前登录用户的用户名，展示到页面中
            axios.get("/user/getUsername.do").then((res) => {
                if (res.data.flag) {
                    this.username = res.data.data;
                }
                axios.post("/menu/findMenuByUser.do?username=" + this.username).then((res) => {
                    if (res.data.flag) {
                        this.menuList = res.data.data;
                    }
                });
            });
        },
        methods: {
            //打开修改密码弹窗
            openEditPwd() {
                this.dialogFormVisible = true;
                this.formData = {};
                this.formData.username = this.username;
            },
            //关闭弹窗
            editCancel() {
                this.dialogFormVisible = false;
            },
            //修改密码
            editPassword() {
                axios.post("/user/editPassword.do", this.formData).then((res) => {
                    if (res.data.flag) {
                        this.$message.success('修改成功');
                        this.dialogFormVisible = false;
                        window.location.href = '/logout.do';
                    } else {
                        this.$message.error('修改失败');
                        this.dialogFormVisible = false;
                    }
                })
            },
            //发送验证码
            sendValidateCode() {
                var telephone = this.formData.telephone;
                var username = this.formData.username;
                if (!checkTelephone(telephone)) {
                    this.$message.error('请输入正确的手机号');
                    return false;
                }
                // validateCodeButton = $("#validateCodeButton")[0];
                var num = 30;
                clock = window.setInterval(this.timeDown(num), 1000); //一秒执行一次
                axios.post("/validateCode/send4EditPwd.do?username=" + username + "&telephone=" + telephone).then((response) => {
                    if (!response.data.flag) {
                        //验证码发送失败
                        this.$message.error('验证码发送失败，用户名或手机号错误');
                        return false;
                    }
                    //计时器
                    let num = 30;
                    clock = window.setInterval(() => {
                        if (num == 0) {
                            this.btn_text = '获取验证码';
                            this.disabled = false;
                            clearInterval(clock);
                        } else {
                            this.disabled = true;
                            this.btn_text = num + 's后重新获取';
                            num--;
                        }
                    }, 1000); //一秒执行一次
                });
            }
        }
    });
    $(function () {
        var wd = 200;
        $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
